/****************************************************************************

 plugin.hpp - Imitates an LV2 plugin. Holds RDF data only.

Copyright (C) Michael R Fisher <mfisher31@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 01222-1307 USA

****************************************************************************/

#ifndef PLUGIN_HPP_
#define PLUGIN_HPP_

#include <string>
#include <vector>
#include <map>

#include <sigc++/signal.h>
#include <rdf.hpp>

struct Port {
  std::string name;
  uint32_t index;
  std::string symbol;
  float default_value;
  float minimum_value;
  float maximum_value;
};

struct PluginInfo {
  std::string name;
  std::string author;
  std::string homepage;
  std::string email;
  std::string license;
  std::string docs;
};

class Plugin
{
public:
  typedef std::map<std::string, uint32_t> map_t;
  typedef std::map<std::string, uint32_t>::iterator miter_t;

  Plugin(const char* plugin_uri)
  : m_uri(plugin_uri), m_bundle(""),
    m_data(),m_ports(),m_valid(false),
    m_symbol_map()
  {
    m_info.name = "";
     m_info.author = "";
     m_info.homepage = "";
     m_info.email= "";
     m_info.license = "";
     m_info.docs = "";
  }

  ~Plugin() {} ;

  /** Opens a bundle and parses it's RDF data.
   */
  bool open_bundle(const char* bundle);


  /** This function queries the plugin's RDF data for all
   * Input Control ports and broadcasts a signal when a
   * control is found.
   */
  bool find_controls();


  /** Returns the symbol map for this Plugin
   */
  map_t* get_symbol_map() { return &m_symbol_map; }


  /** Returns useful information about the plugin.
   */
  PluginInfo* get_info() { return &m_info; }


  bool is_valid() { return m_valid; }


  std::string name() { return m_info.name; }

  /** This is emitted when a control input is found
   */
  sigc::signal<void,Port&> signal_found_control;

protected:
  bool scan_ports(std::string& parent);
  void get_data_files();
  void print_port_data();
  bool parse_data_files();
  bool fill_plugin_info();
  std::string get_name();

  bool m_valid;

  std::vector<std::string> m_data_files;
  std::string m_uri;
  std::string m_bundle;
  PAQ::RDFData m_data;

  std::vector<Port> m_ports;
  map_t m_symbol_map;
  PluginInfo m_info;

};

#endif /* PLUGIN_HPP_ */
